﻿/*
Copyright (C) 2008 Kamal Singh.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

var b = 1;
var anim;

function view_onOpen() {
	countdown();
	//setInterval("countdown();", 1000 * 60);
  setInterval("fadeImage();", 1000 * 10);
}

function countdown() {
	var now = new Date();
	var then = new Date("August 8, 2008 00:00:00");
	var difference = new Date();
	difference.setTime(Math.abs(then.getTime() - now.getTime()));
 
	if (then.getTime() - now.getTime() < 0) {
		difference.setTime(0);
	}
	timeDifference = difference.getTime();
	dRemain	= Math.floor(timeDifference / (1000 * 60 * 60 * 24));
	days.innerText = dRemain + " days to go";
}

function fadeImage()
{
  var pic_uri;
  b++;
  debug.trace(b);
  if(b > 5) {
    b = 1;
  }
  pic_uri = "b" + b + ".png";
  img1.src = pic_uri;

  if (anim == null) {
    debug.trace("starting the animation");
    anim = beginAnimation("anima()", 255, 100, 5000);
  }
  else {
    debug.trace("cancelling the animation");
    cancelAnimation(anim);
    anim = null;
    debug.trace("starting the animation");
    anim = beginAnimation("anima()", 255, 100, 5000);
  }
}

function anima() {
  img1.opacity = event.value;
}